package com.gz.furn.service.impl;

import com.gz.furn.bean.Furn;
import com.gz.furn.bean.FurnExample;
import com.gz.furn.dao.FurnMapper;
import com.gz.furn.service.FurnService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class FurnServiceImpl implements FurnService {

    @Resource
    private FurnMapper furnMapper;

    @Override
    public void save(Furn furn) {
        furnMapper.insertSelective(furn);
    }

    @Override
    public List<Furn> findAll() {
        //如果传入null，表示返回所有信息
        List<Furn> furns = furnMapper.selectByExample(null);
        return furns;
    }

    @Override
    public void update(Furn furn) {
        furnMapper.updateByPrimaryKeySelective(furn);
    }

    @Override
    public void delete(Integer id) {
        furnMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Furn> findByCondition(String name) {
        FurnExample furnExample = new FurnExample();
        //通过Criteria对象可以设置查询的条件
        FurnExample.Criteria criteria = furnExample.createCriteria();
        //判断
        if(StringUtils.hasText(name)){
            criteria.andNameLike("%"+name+"%");
        }
        return furnMapper.selectByExample(furnExample); 
    }
}
